package com.pomr.dao.base;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;

import com.pomr.util.page.Page;
/**
 * dao层公共接口
 * @author wgchao
 * 2017.12.22
 *
 */
public interface BaseDao {
	
	/** 
     * <b>function:</b>增加一个entity对象，返回是否添加成功 
     * @author ending 
     * @param T 对象类型 
     * @param entity 实体类 
     * @return boolean true/false 
     * @throws Exception 
     * */  
    public <T> boolean add(T entity) throws Exception;  
    /** 
     * <b>function:</b>增加一个entity对象，返回String主键 
     * @author ending 
     * @param T 对象类型 
     * @param entity 实体类 
     * @return String 
     * @throws Exception 
     * */  
    public <T> String addStringKey(T entity) throws Exception;  
    /** 
     * <b>function:</b>增加一个entity对象，返回Integer主键 
     * @author ending 
     * @param T 对象类型 
     * @param entity 实体类 
     * @return Integer 
     * @throws Exception 
     * */  
    public <T> Integer addNumKey(T entity) throws Exception;  
    /** 
     * <b>function:</b>传入一个hql语句，返回影响多少条数据 
     * @author ending 
     * @param hql 
     * @return int 
     * @throws Exception 
     * */  
    public int executeData(String hql) throws Exception;  
    /** 
     * <b>function:</b>传入一个hql语句，返回list集合 
     * @author ending 
     * @param hql 
     * @return List 
     * @throws Exception 
     * */  
    public <T> List<T> findByHql(String hql) throws Exception;  
    
    /** 
     * <b>function:</b>传入一个hql语句，返回list集合 (参数预处理 主要是时间段)
     * @author ending 
     * @param hql 
     * @return List 
     * @throws Exception 
     * */ 
    public <T> List<T> findByHqlWithDate(String hql,Map<String, Date> map,int page) throws Exception;
    
    /** 
     * <b>function:</b>传入一个hql语句，返回list集合  不走缓存
     * @author ending 
     * @param hql 
     * @return List 
     * @throws Exception 
     * */  
    public <T> List<T> findByHqlNoCache(String hql) throws Exception;  
    
    /** 
     * <b>function:</b>传入一个hql语句，返回list集合  不走缓存
     * @author ending 
     * @param hql 
     * @return List 
     * @throws Exception 
     * */  
    public <T> List<T> findByHqlNoCacheWithDate(String hql,Map<String, Date> map) throws Exception;  
    
    /** 
     * <b>function:</b>执行sql语句，实行增，删，改 
     * @author ending 
     * @param sql 
     * @return Integer 
     * @throws Exception 
     * */  
    public int executeBySql(String sql) throws Exception;  
    /**  
     * <b>function:</b>执行sql查询语句，获取list集合 
     * @author ending 
     * @param sql 
     * @return List 
     * @throws Exception 
     * */  
    public <T> List<T> findBySql(String sql, Class y) throws Exception;  
    /**  
     * <b>function:</b>修改实体的数据，返回boolean结果 
     * @author ending 
     * @param entity 
     * @return boolean 
     * @throws Exception 
     * */  
    public <T> boolean editEntity(T entity) throws Exception;  
    /**  
     * <b>function:</b>执行hql语句，返回boolean结果 
     * @author ending 
     * @param hql 
     * @return boolean 
     * @throws Exception 
     * */  
    public boolean editHql(String hql) throws Exception;  
    /**  
     * <b>function:</b>执行hql语句，返回执行结果影响的行数 
     * @author ending 
     * @param hql 
     * @return Integer 
     * @throws Exception 
     * */  
    public int editNumHql(String hql) throws Exception;  
    /**  
     * <b>function:</b>传入要删除的实体，返回boolean结果 
     * @author ending 
     * @param entity 
     * @return boolean 
     * @throws Exception 
     * */  
    public <T> boolean removeEntity(T entity) throws Exception;  
    /**  
     * <b>function:</b>传入要实体类的class和int主键，返回具体实体 
     * @author ending 
     * @param clazz 
     * @param id 
     * @return T 
     * @throws Exception 
     * */  
    public <T> T getById(Class<T> clazz,int id) throws Exception;  
    /**  
     * <b>function:</b>传入要实体类的class和String主键，返回具体实体 
     * @author ending 
     * @param clazz 
     * @param id 
     * @return T 
     * @throws Exception 
     * */  
    public <T> T getById(Class<T> clazz,String id) throws Exception;  
    /**  
     * <b>function:</b>传入要实体类的class和Serializable主键，返回具体实体 
     * @author ending 
     * @param clazz 
     * @param id 
     * @return T 
     * @throws Exception 
     * */  
    public <T> T getById(Class<T> clazz,Serializable id) throws Exception;  
    /**  
     * <b>function:</b>传入hql语句，返回实体 
     * @author ending 
     * @param hql 
     * @return T 
     * @throws Exception 
     * */  
    public <T> T getByHql(String hql) throws Exception;  
    /**  
     * <b>function:</b>传入hql语句，返回实体集合 
     * @author ending 
     * @param hql 
     * @return List 
     * @throws Exception 
     * */  
    public <T> List<T> getList(String hql) throws Exception;  
    /**  
     * <b>function:</b>传入sql语句删除数据，返回执行结果 
     * @author ending 
     * @param hql 
     * @return boolean 
     * @throws Exception 
     * */  
    public boolean remove(String hql) throws Exception;  
    
//    /**  
//     * <b>function:</b>传入hql语句删除数据，返回执行结果 
//     * @author ending 
//     * @param hql 
//     * @return boolean 
//     * @throws Exception 
//     * */  
//    public boolean removeHql(String hql) throws Exception;  
    
    /**  
     * <b>function:</b>动态查询 
     * @author ending 
     * @param clazz 
     * @return List 
     * @throws Exception 
     * */  
    public <T> List<T> getList(Class<T> clazz) throws Exception;  
    /**  
     * <b>function:</b>传入hql查询语句和object数组的参数，list返回结果 
     * @author ending 
     * @param hql 
     * @param obj 
     * @return List 
     * @throws Exception 
     * */  
    public <T> List<T> getList(String hql,Object[] obj) throws Exception;  
    /**  
     * <b>function:</b>传入查询语句和查询总条数的hql，当前页数，一页显示多少数据，用list集合返回 
     * @author ending 
     * @param queryHql 
     * @param queryCountHql 
     * @param firstResult 
     * @param maxResult 
     * @return List 
     * @throws Exception 
     * */  
    public List<?> showPage(String queryHql,String queryCountHql,int firstResult,int maxResult) throws Exception;  
    /**  
     * <b>function:</b>传入查询语句和查询总条数的hql，page分页对象，返回分页对象
     * @author ending 
     * @param queryHql 
     * @param queryCountHql 
     * @param page 
     * @return Page 返回分页对象 
     * @throws Exception 
     * */  
    public <T> Page<T> showPage(String queryHql,String queryCountHql,Page<T> page) throws Exception; 
    
    public <T> Page<T> showPageParam(String queryHql, String queryCountHql, Page<T> page, Map<String, Object> params) throws Exception;
    /**  
     * <b>function:</b>传入查询语句和查询总条数的hql，DetachedCriteria动态查询条件进行分页，用list集合返回 
     * @author ending 
     * @param queryHql 
     * @param criteria 
     * @param firstResult 
     * @param maxResult 
     * @return List 
     * @throws Exception 
     * */  
    @SuppressWarnings("rawtypes")  
    public List showPage(String queryHql,DetachedCriteria criteria,int firstResult,int maxResult) throws Exception;  
    /**  
     * <b>function:</b>传入查询语句和查询总条数的hql，DetachedCriteria动态查询条件进行分页，分页对象page，用list集合返回 
     * @author ending 
     * @param queryHql 
     * @param criteria 
     * @param page 
     * @return List 
     * @throws Exception 
     * */  
    public <T> List<T> showPage(String queryHql,DetachedCriteria criteria,Page<T> page) throws Exception;  
    /**  
     * <b>function:</b>传入DetachedCriteria动态查询条件，用list集合返回 
     * @author ending 
     * @param criteria 
     * @return List 
     * @throws Exception 
     * */  
    public <T> List<T> find(DetachedCriteria criteria) throws Exception;  
    /**  
     * <b>function:</b>提供session使用 
     * @author ending 
     * @return Session 
     * */  
    public Session session();  
    /**
     * <b>function:</b>批量更新操作 使用jdbc方式增加效率
     * @param preSql 预处理sql
     * @param list 参数集合(按顺序)
     * @param paramNum 参数数量
     * @param batchNum 一次最大执行数
     * @return
     */
    public boolean updateorsave(String preSql,List<List> list, int paramNum, int batchNum);
    
    /**
     * 更新或保存数据
     * @param entity
     * @return
     * @throws Exception
     */
    public <T> boolean saveOrUpdateEntity(T entity) throws Exception;

    /**
     * 批量更新或新增
     * @param list
     * @return
     * @throws Exception
     */
    public <T> boolean batchSaveOrUpdate(final List<T> list) throws Exception;

    public boolean editHql(String hql, Object[] objs) throws Exception;

}
